package com.domain.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.aliyuncs.exceptions.ClientException;
import com.domain.common.AppLogger;
import com.domain.common.Comments;
import com.domain.common.Const;
import com.domain.common.Result;
import com.domain.dao.*;
import com.domain.pojo.*;
import com.domain.service.BillService;
import com.domain.service.PublishService;
import com.domain.service.PushMessageService;
import com.domain.service.UsersService;
import com.domain.utils.*;
import com.domain.utils.alipay.AlipayUtil;
import com.domain.utils.jiguang.Jdpush;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;

@Service
@Transactional(rollbackFor = Exception.class)
public class PublishServiceImpl implements PublishService {

    /**
     * 日志
     */
    private static Logger logger = AppLogger.getLogger(PublishServiceImpl.class.getSimpleName(), Level.INFO.toString(), true);
    @Autowired
    private PublishMapper publishMapper;

    @Autowired
    private UsersMapper usersMapper;

    @Autowired
    private CommentMapper commentMapper;

    @Autowired
    private PublishAcceptanceMapper publishAcceptanceMapper;


    @Autowired
    private UsersFillterPublishUsersMapper usersFillterPublishUsersMapper;


    @Autowired
    private BillService billService;


    @Autowired
    private UsersHelpMapper usersHelpMapper;

    @Autowired
    private PushMessageService pushMessageService;


    @Autowired
    private FollowMapper followMapper;

    @Autowired
    private UsersFillterUsersMapper usersFillterUsersMapper;

    @Autowired
    private ContactsMapper contactsMapper;
    @Autowired
    private UsersService usersService;

    @Autowired
    private UsersWalletMapper usersWalletMapper;

    @Autowired
    private UsersGroupInfoMapper usersGroupInfoMapper;

    @Autowired
    private UsersSmsRecordMapper usersSmsRecordMapper;


    /**
     * 发布求助
     *
     * @param userId
     * @param typeId
     * @param publishTitle
     * @param publishContent
     * @param filterUserId
     * @param longitude
     * @param latitude
     * @param itIsPaid
     * @param cityName
     * @param images
     * @param money
     * @param
     * @return
     */
    @Override
    public Result savePublish(String userId, String typeId, String publishTitle, String publishContent, String filterUserId, String longitude, String latitude, String itIsPaid, String cityName, String images, String money) throws ClientException {
        logger.info("userId****" + userId);
        logger.info("typeId****" + typeId);
        logger.info("publishTitle****" + publishTitle);
        logger.info("publishContent****" + publishContent);
        logger.info("filterUserId****" + filterUserId);
        logger.info("longitude****" + longitude);
        logger.info("latitude****" + latitude);
        logger.info("itIsPaid****" + itIsPaid);
        logger.info("cityName****" + cityName);
        logger.info("images****" + images);
        logger.info("money****" + money);
        Publish p = new Publish();
        String publishId = UUIDUtils.getRandomUUID();
        p.setId(publishId);
        p.setTitle(publishTitle);
        p.setCityName(cityName);
        p.setContent(publishContent);
        p.setCreatTime(new Date());
        p.setImages(images);
        p.setItIsPaid(new Integer(itIsPaid));//是否有偿
        p.setLatitude(latitude);
        p.setLongitude(longitude);
        p.setSpareOne(typeId);
        p.setSpareTwo(new BigDecimal(money));
        p.setType(Comments.PUBLISH_TYPE_HAVE_IN_HAND);
        p.setState(Comments.STATE_NORMAL);
        p.setUserId(userId);
        int result = publishMapper.insertSelective(p);
        if (result > 0) {
            //判断该用户是否发布得是第一条
            List<Publish> publishes = publishMapper.selectPublishByUserId(userId);
            Users users = usersMapper.selectByPrimaryKey(userId);
            if (publishes.size() == 1) {
                //发送好友短信
                List<Contacts> contactsList = contactsMapper.selectByContUser(userId);
                /*for (Contacts c : contactsList) {
                    if (NotNullUtils.isMobile(c.getSpareOne())) {
                        //发送短信
                        SmsVariableResponse response = SmsChuangLan.sendMessage(c.getSpareOne(), users.getName(), "2");
                        //短信发送成功记录发送记录
                        if (!NotNullUtils.isNotNullObject(response.getErrorMsg())) {
                            UsersSmsRecord sm = new UsersSmsRecord();
                            sm.setId(UUIDUtils.getRandomUUID());
                            sm.setCreatTime(new Date());
                            sm.setSendUsersId(userId);
                            sm.setUsersPhone(users.getPhone());
                            sm.setSendUsersPhone(c.getSpareOne());
                            usersSmsRecordMapper.insertSelective(sm);
                        }
                    }
                }*/
            }
        }
        //保存该发布的过滤的好友
        //filterUserId，得到json数组
        if (NotNullUtils.isNotNullObject(filterUserId)) {
            String[] fillterUserId = filterUserId.split(",");
            for (int i = 0; i < fillterUserId.length; i++) {
                UsersFillterPublishUsers ufpu = new UsersFillterPublishUsers();
                ufpu.setId(UUIDUtils.getRandomUUID());
                ufpu.setFillterUserId(fillterUserId[i]);
                ufpu.setPublishId(publishId);
                ufpu.setCreatTime(new Date());
                ufpu.setUserId(userId);
                usersFillterPublishUsersMapper.insertSelective(ufpu);
            }
        }
        return Result.success(publishId);
    }

    /**
     * 我的发布列表
     *
     * @param userId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public Result getUsersPublish(String userId, String pageNum, String pageSize) {
        PageHelper.startPage(new Integer(pageNum), new Integer(pageSize));
        List<Map<String, Object>> publishMaps = publishMapper.selectByUserIdMaps(userId);
        List<Map<String, Object>> mapList = new ArrayList<>();
        //获取发布得评论条数
        for (Map<String, Object> maps : publishMaps) {
            List<Comment> comments = commentMapper.selectBypublishId(maps.get("pId").toString());
            maps.put("commentSize", comments.size());
            List<Map<String, Object>> publishAcceptances = publishAcceptanceMapper.selectByAppentUsersId(maps.get("pId").toString());
            maps.put("publishAcceptancesSize", publishAcceptances.size());
            mapList.add(maps);
        }
        PageInfo pageResult = new PageInfo(mapList);
        return Result.success("操作成功", pageResult.getList());
    }

    /**
     * 获取用户发布详情
     *
     * @param userId    用户id
     * @param publishId 发布id
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public Result getUserPublishDetail(String userId, String publishId, String helpUsersId, String connectionUserId) {
        Map<String, Object> maps = new HashMap<>();
        //发布信息
        Publish publish = publishMapper.selectByPrimaryKey(publishId);
        //发布者信息
        Users users = usersMapper.selectByPrimaryKey(publish.getUserId());
        //评论数量
        List<Comment> size = commentMapper.selectBypublishId(publishId);
        maps.put("userId", users.getId());
        maps.put("userName", users.getName());
        maps.put("headImage", users.getHeadImage());
        maps.put("gender", users.getGender());
        maps.put("birthday", DateUtils.getAgeByBirthDay(users.getBirthday()));
        maps.put("city", users.getCity());
        maps.put("industry", users.getIndustry());
        maps.put("personalLabel", NotNullUtils.sliptList(users.getPersonalLabel()));
        //发布信息
        maps.put("typeId", publish.getSpareOne());
        maps.put("publishId", publish.getId());
        maps.put("publishTitle", publish.getTitle());
        maps.put("publishContent", publish.getContent());
        maps.put("images", NotNullUtils.sliptList(publish.getImages()));
        String time = RelativeDateFormat.format(publish.getCreatTime());
        maps.put("publishTime", time);
        maps.put("publishFowordCount", publish.getForwardCount());
        maps.put("publishCity", publish.getCityName());
        maps.put("commentSize", size.size());
        maps.put("helpResPackage", publish.getSpareTwo());
        maps.put("itisPaid", publish.getItIsPaid());
        maps.put("publishType", publish.getType());
        //判断是否转发
        List<UsersHelp> list = usersHelpMapper.selectHelpIdAndPublish(userId, publishId);
        if (list.size() > 0) {
            maps.put("itisHelp", "YES");
        } else {
            maps.put("itisHelp", "NO");
        }
        //是否关注
        List<Follow> followList = followMapper.selectByUserAndPublish(userId, publishId);
        if (followList.size() > 0) {
            maps.put("itisFollow", "YES");
        } else {
            maps.put("itisFollow", "NO");
        }
        if (userId.equals(users.getId())) {
            maps.put("usersHumanChain", null);
        } else {
            maps.put("usersHumanChain", usersService.getUsersHumanChain(userId, publish.getUserId(), helpUsersId, connectionUserId));
        }

        maps.put("acceptanceUsersInfo", publishAcceptanceMapper.selectByAppentUsersId(publish.getId()));
        //是否受理
        if (NotNullUtils.isNotNullObject(publishAcceptanceMapper.selectByAcceptanIdAndPublishId(userId, publishId))) {
            maps.put("itisAppent", "YES");
        } else {
            maps.put("itisAppent", "NO");
        }
        return Result.success("操作成功", maps);
    }


    /**
     * 完成帮忙
     *
     * @param userId
     * @param publishId
     * @return
     */
    @Override
    public Result completePublish(String userId, String publishId, String groupId) {
        logger.info("groupId************++" + groupId);
        //获取去重的帮转人id
        List<UsersHelp> usersHelps = usersHelpMapper.selectByDistinct(publishId);
        //发布的信息
        Publish pu = publishMapper.selectByPrimaryKey(publishId);
        //用户信息
        Users userss = usersMapper.selectByPrimaryKey(userId);
        //帮转人更新靠谱值
        for (UsersHelp up : usersHelps) {
            Users users = usersMapper.selectByPrimaryKey(up.getHelpId());
            String valuse = "5";
            BigDecimal value = ArithmeticUtil.add(users.getSpectralValue().toString(), valuse);
            users.setSpectralValue(new Integer(value.toString()));
            users.setUpdateTime(new Date());
            usersMapper.updateByPrimaryKeySelective(users);
            //增加靠谱值信息
            pushMessageService.addSystemMessage(up.getHelpId(), userId, "恭喜您获取靠谱值+" + valuse + "", "获得靠谱值", "", Const.spectral_value, UUIDUtils.getRandomUUID(), valuse);
        }
        logger.info("发红包开始***************************************");
        //获取每个人发红包的钱数
        List<BigDecimal> money = HongBaoAlgorithm.math(pu.getSpareTwo(), usersHelps);
        for (int i = 0; i < money.size(); i++) {
            //红包钱数大于零
            if (money.get(i).doubleValue() > 0) {
                for (int j = 0; j < usersHelps.size(); j++) {
                    if (i == j) {
                        String pushId = UUIDUtils.getRandomUUID();
                        Jdpush.sendToAliasList(usersHelps.get(j).getHelpId(), "" + userss.getName() + "帮忙信息已经完成,感谢您得帮转", "pushId", pushId, "pushType", Const.getRed_package, "bigTypeKey", Const.THANK_MESSAGE, "红包通知");
                        //推送成功添加推送记录
                        pushMessageService.addAcknowledgeMessage(usersHelps.get(j).getHelpId(), pu.getUserId(), "" + userss.getName() + "帮忙信息已经完成,感谢您得帮转", "红包通知", money.get(i).toString(), Const.getRed_package, pushId, userss.getName());
                    }
                }
            }
        }
        //受理人更新靠谱值
        if (NotNullUtils.isNotNullObject(groupId)) {
            String[] strings = groupId.split(",");
            for (String s : strings
            ) {
                //通过获取的群号查询受理人的信息
                UsersGroupInfo usersGroupInfo = usersGroupInfoMapper.selectByCreatGroupId(s);
                if (NotNullUtils.isNotNullObject(usersGroupInfo)) {
                    //发布人信息
                    Users user = usersMapper.selectByPrimaryKey(usersGroupInfo.getUsersId());
                    //获取受理人的信息
                    Users users = usersMapper.selectByPrimaryKey(usersGroupInfo.getSpareOne());
                    //更新受理人的靠谱值 100
                    String valuse = "100";
                    BigDecimal value = ArithmeticUtil.add(users.getSpectralValue().toString(), valuse);
                    users.setSpectralValue(new Integer(value.toString()));
                    users.setUpdateTime(new Date());
                    usersMapper.updateByPrimaryKeySelective(users);
                    //增加靠谱值信息
                    pushMessageService.addSystemMessage(users.getId(), userId, "恭喜您获取靠谱值+" + valuse + "", "获得靠谱值", "", Const.spectral_value, UUIDUtils.getRandomUUID(), valuse);
                    //推送消息至受理人发布消息完成
                    String pushId = UUIDUtils.getRandomUUID();
                    Jdpush.sendToAliasList(users.getId(), "您成功帮助了" + user.getName() + "", "pushId", pushId, "pushType", Const.help_finish, "bigTypeKey", Const.PUBLISH_MESSAGE, "帮忙通知");
                    pushMessageService.addPublishiMessage(users.getId(), users.getId(), "您成功帮助了" + user.getName() + "", "帮忙通知", "", Const.help_finish, pushId, user.getName());
                    //修改受理状态
                    PublishAcceptance pe = publishAcceptanceMapper.selectByAcceptanIdAndPublishId(users.getId(), publishId);
                    if (NotNullUtils.isNotNullObject(pe)) {
                        pe.setSpareOne(Comments.ADOPT_YES);
                        pe.setUpdateTime(new Date());
                        publishAcceptanceMapper.updateByPrimaryKeySelective(pe);
                    }
                }
            }
        }
        //修改发布状态
        Publish p = new Publish();
        p.setId(pu.getId());
        p.setType(Comments.PUBLISH_TYPE_COMLETED);
        p.setUpdateTime(new Date());
        publishMapper.updateByPrimaryKeySelective(p);
        return Result.success();
    }

    /**
     * 帮转红包支付
     *
     * @param userId       用户id
     * @param total_amount
     * @return
     */
    @Override
    public Result helpRedPacakgePay(String userId, String total_amount) throws AlipayApiException {
        logger.info("usersid++" + userId);
        logger.info("total_amount++" + total_amount);
        AlipayTradeAppPayResponse response = AlipayUtil.creatAlipayOrder("帮转红包支付", "帮转红包支付", total_amount);
        return Result.success(response.getBody());
    }

    /**
     * 发布补加红包
     *
     * @param userId
     * @param money
     * @param publishId
     * @return
     */
    @Override
    public Result helpRedPacakgeSupplement(String userId, String money, String publishId) throws AlipayApiException {
        AlipayTradeAppPayResponse response = AlipayUtil.creatAlipayOrder("补加帮转红包付款", "补加帮转红包付款", money);
        return Result.success(response.getBody());
    }

    /**
     * 完成帮忙判断
     *
     * @param userId
     * @param publishId
     * @return
     */
    @Override
    public Result judgeCompletePublish(String userId, String publishId) {
        //获取去重的帮转人id
        List<UsersHelp> usersHelps = usersHelpMapper.selectByDistinct(publishId);
        //发布的信息
        Publish pu = publishMapper.selectByPrimaryKey(publishId);
        //判断发布的红包是否大于零
        if (pu.getSpareTwo().doubleValue() > 0 && usersHelps.size() > 0) {
            //红包不足缺的钱数（帮转人*0.01-发布红包的钱数）
            //获取每个人发红包的钱数
            String money = HongBaoAlgorithm.maths(pu.getSpareTwo(), usersHelps.size());
            if (money == null) {
                return Result.publicResult(401, "红包余额不足，请补发红包");
            }
        } else if (pu.getSpareTwo().doubleValue() > 0 && usersHelps.size() <= 0) {
            //该发布没有人帮转
            //没有人帮忙转发  余额退回至发布人
            Users user = usersMapper.selectByPrimaryKey(pu.getUserId());
            String pushId = UUIDUtils.getRandomUUID();
            //推送至发布人余额退回信息
            Jdpush.sendToAliasList(user.getId(), "您的红包余额已经退回到您的账户", "pushId", pushId, "pushType", Const.red_pacakge_return, "biTypeKey", Const.SYSTEM_MESSAGE, "红包余额退回");
            //推送成功添加推送记录
            pushMessageService.addSystemMessage(user.getId(), "", "您的红包余额已经退回到您的账户", "红包余额退回", publishId, Const.red_pacakge_return, pushId, "");
            //添加账单信息
            billService.addBill("", user.getId(), "红包余额退款", Comments.SERZERBAL_PUT, pu.getSpareTwo().toString(), Const.RED_PACKAGE_ICONS);
            //修改账户信息
            UsersWallet usersWallet = usersWalletMapper.selectByUserId(pu.getUserId());
            BigDecimal money = ArithmeticUtil.add(usersWallet.getBalance().toString(), pu.getSpareTwo().toString());
            usersWallet.setBalance(money);
            usersWalletMapper.updateByPrimaryKeySelective(usersWallet);
        }
        return Result.success();
    }

    /**
     * 删除帮忙
     *
     * @param userId
     * @param publishId
     * @return
     */
    @Override
    public Result deletePublish(String userId, String publishId) {
        Publish pe = publishMapper.selectByPrimaryKey(publishId);
        //系统时间-创建时间的分钟数
        Long s = (System.currentTimeMillis() - pe.getCreatTime().getTime()) / (1000 * 60);
        if (s > 5) {
            return Result.publicResult(401, "该发布已经发布时间五分钟");
        }
        //删除帮忙（修改状态）
        Result result = judgeCompletePublish(userId, publishId);
        if (result.getCode() == 200) {
            //删除帮忙（修改状态）
            Publish pu = new Publish();
            pu.setId(publishId);
            pu.setUpdateTime(new Date());
            pu.setState(Comments.STATE_DELETE);
            publishMapper.updateByPrimaryKeySelective(pu);
        }
        return Result.success();
    }

    /**
     * 获取过滤得好友列表
     *
     * @param usersId
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public Result getFriendsLists(String usersId, String phoneNum, String name, String pageNum, String pageSize) {
        //获取我过滤得好友
        PageHelper.startPage(new Integer(pageNum), new Integer(pageSize));
        //获取我的app好友
        Map<String, Object> map = new HashMap<>();
        map.put("userId", usersId);
        if (NotNullUtils.isNotNullObject(phoneNum)) {
            map.put("num", phoneNum);
        }
        if (NotNullUtils.isNotNullObject(name)) {
            map.put("names", name);
        }
        List<Map<String, Object>> contactsList = contactsMapper.selectBySerch(map);
        PageInfo pageInfo = new PageInfo(contactsList);
        return Result.success(pageInfo.getList());
    }


    /**
     * 帮转红包 退款
     *
     * @param userId      用户id
     * @param returnMoney 退款金额
     * @return
     */
    @Override
    public Result payReturn(String userId, String returnMoney) {
        //退款成功增加账单信息
        UsersWallet us = usersWalletMapper.selectByUserId(userId);
        BigDecimal newMoney = ArithmeticUtil.add(us.getBalance().toString(), returnMoney);
        us.setBalance(newMoney);
        us.setUpdateTime(new Date());
        int result = usersWalletMapper.updateByPrimaryKeySelective(us);
        if (result > 0) {
            billService.addBill("", userId, "帮转红包退回", Comments.SERZERBAL_PUT, returnMoney, Const.RED_PACKAGE_ICONS);
        }
        return Result.success();
    }

    /**
     * 帮忙完成获取群id
     *
     * @param publishId 发布id
     * @param usersId   用户id
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public Result getGroupIid(String publishId, String usersId) {
        List<String> strings = new ArrayList<>();
        List<UsersGroupInfo> infos = usersGroupInfoMapper.selectByCreatGroupAndUsersId(publishId, usersId);
        for (UsersGroupInfo uf : infos
        ) {
            strings.add(uf.getGroupId());
        }
        return Result.success(strings);
    }

    /**
     * 完成帮忙答谢支付
     *
     * @param userId       用户id
     * @param total_amount 答谢的钱数
     * @param acUsersId    答谢的人的id
     * @return
     */
    @Override
    public Result acknowledge(String userId, String total_amount, String acUsersId) throws AlipayApiException {
        AlipayTradeAppPayResponse response = AlipayUtil.creatAlipayOrder("答谢支付", "答谢支付", total_amount);
        return Result.success(response.getBody());
    }

    /**
     * 公益发布
     *
     * @return
     */
    @Override
    public Result addPublishWelfare(String strJson) {
        JSONObject j = JSONObject.parseObject(strJson);
        String usersName = j.getString("publishName");
        String publishPhone = j.getString("publishPhone");
        String headImage = j.getString("headImage");
        String publishTitle = j.getString("publishTitle");
        String detail = j.getString("detail");
        String images = j.getString("images");
        String city = j.getString("city");
        String publishType = j.getString("publishType");
        String userscity = j.getString("userscity");
        Users user = usersMapper.selectByUserPhone(publishPhone);
        String usersuuid = UUIDUtils.getRandomUUID();
        //添加发布的用户
        if (!NotNullUtils.isNotNullObject(user)) {
            Users users = new Users();
            users.setId(usersuuid);
            users.setName(usersName);
            users.setBirthday(new Date());
            users.setHeadImage(headImage);
            users.setPhone(publishPhone);
            users.setCity(userscity);
            usersMapper.insertSelective(users);
        }
        //添加发布信息
        Publish p = new Publish();
        p.setId(UUIDUtils.getRandomUUID());
        if (NotNullUtils.isNotNullObject(user)) {
            p.setUserId(user.getId());
        } else {
            p.setUserId(usersuuid);
        }
        p.setCityName(city);
        p.setContent(detail);
        p.setImages(images);
        p.setType(Comments.PUBLISH_TYPE_HAVE_IN_HAND);
        p.setTitle(publishTitle);
        p.setCreatTime(new Date());
        p.setState("3");
        if ("生命接力".equals(publishType)) {
            p.setSpareOne("9");
        }
        if ("寻亲团圆".equals(publishType)) {
            p.setSpareOne("10");
        }
        if ("爱心助学".equals(publishType)) {
            p.setSpareOne("11");
        }
        publishMapper.insertSelective(p);
        return Result.success();
    }

    /**
     * 发布详情(公益模块)
     *
     * @param userId
     * @param publishId
     * @return
     */
    @Override
    public Result getUserPublishDetailG(String userId, String publishId) {
        Map<String, Object> p = publishMapper.selectByPrimaryKeys(publishId);
        //关注次数
        p.put("followSize", followMapper.selectByPublishId(publishId).size());
        //评论次数
        p.put("commentsSize", commentMapper.selectBypublishId(publishId).size());
        //发布时间
        p.put("ptime", RelativeDateFormat.format(DateUtils.strToDate(p.get("ptime").toString(), "yyyy-MM-dd HH:mm:ss")));
        //发布照片
        p.put("pimages", NotNullUtils.sliptList(p.get("pimages").toString()));
        //发布标签
        String laber = p.get("ptype").toString();
        if ("9".equals(laber)) {
            p.put("laber", "生命接力");
        }
        if ("10".equals(laber)) {
            p.put("laber", "寻亲团圆");
        }
        if ("11".equals(laber)) {
            p.put("laber", "爱心助学");
        }
        //是否受理
        if (NotNullUtils.isNotNullObject(publishAcceptanceMapper.selectByAcceptanIdAndPublishId(userId, publishId))) {
            p.put("itisAppent", "YES");
        } else {
            p.put("itisAppent", "NO");
        }
        //是否关注
        List<Follow> followList = followMapper.selectByUserAndPublish(userId, publishId);
        if (followList.size() > 0) {
            p.put("itisFollow", "YES");
        } else {
            p.put("itisFollow", "NO");
        }
        //该发布转发和受理得人
        List<Contacts> c = contactsMapper.selectByUsersIdAndType(userId);
        //用户的app好友
        List<Map<String, Object>> mapsList = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        for (Contacts cs : c
        ) {
            //帮转列表
            List<UsersHelp> list = usersHelpMapper.selectByDistinct(publishId);
            for (UsersHelp u : list) {
                if (cs.getSpareTwo().equals(u.getHelpId())) {
                    Users user = usersMapper.selectByPrimaryKey(u.getHelpId());
                    map.put("usersHead", user.getHeadImage());
                    map.put("usersName", user.getName());
                }
            }
            //受理列表
            List<PublishAcceptance> alist = publishAcceptanceMapper.selectByPublish(publishId);
            for (PublishAcceptance pu : alist
            ) {
                if (pu.getAcceptanceId().equals(cs.getSpareTwo())) {
                    Users users = usersMapper.selectByPrimaryKey(pu.getAcceptanceId());
                    map.put("usersHead", users.getHeadImage());
                    map.put("usersName", users.getName());
                }
            }
        }
        mapsList.add(map);
        p.put("list", mapsList);
        return Result.success(p);
    }

}

